<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
  <head>
 	<base href="<%=basePath%>">
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/xadmin.js"></script>
  </head>
  
  <body class="layui-anim layui-anim-up">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="findPurchaselistByPage">
          <input class="layui-input" placeholder="采购日期" name="purchaselist.purchaseTime" id="purchaseTime" >
          <input type="text" name="purchaselist.purchaseId"  placeholder="请输入采购编号" autocomplete="off" class="layui-input">
          <input type="text" name="purchaselist.invoiceNumber"  placeholder="请输入发票编号" autocomplete="off" class="layui-input">
          <input type="text" name="purchaselist.supplierName"  placeholder="请输入供应商名称" autocomplete="off" class="layui-input">
          <input type="text" name="purchaselist.purchasePerson"  placeholder="请输入采购人员" autocomplete="off" class="layui-input">
          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('添加采购单','./purchase/purchase-add.jsp',600,400)"><i class="layui-icon"></i>添加</button>
        <span class="x-right" style="line-height:40px">共有数据：${totalPurchase } 条</span>
      </xblock>
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>采购编号</th>
            <th>采购时间</th>
            <th>结算方式</th>
            <th>发票金额</th>
            <th>发票编号</th>
            <th>实付金额</th>
            <th>进货单号</th>
            <th>供应商名称</th>
            <th>采购人员</th>
            <th>发票图片</th>
            <th>合同图片</th>
            <th>运费</th>
            <th>操作</th></tr>
        </thead>
        <tbody>
        <c:forEach var="p" items="${purchaselists }">
          <tr>
            <td>
              <div class="layui-unselect layui-form-checkbox" id="${p.purchaseId }" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>${p.purchaseId }</td>
            <td>${p.purchaseTime }</td>
            <td>${p.payType }</td>
            <td>${p.invoiceAmount }</td>
            <td>${p.invoiceNumber }</td>
            <td>${p.realpay }</td>
            <td>${p.stockNumber }</td>
            <td>${p.supplierName }</td>
            <td>${p.purchasePerson }</td>
            <td>${p.invoicePhoto }</td>
            <td>${p.contractPhoto }</td>
            <td>${p.freight }</td>
            <td class="td-manage">
              <a title="编辑"  onclick="x_admin_show('编辑','member-edit.html',600,400)" href="javascript:;">
                <i class="layui-icon">&#xe642;</i>
              </a>
              <a title="删除" onclick="member_del(this,'${p.purchaseId }')" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>
              </a>
            </td>
          </tr>
         </c:forEach>
          
          
        </tbody>
      </table>
      
      <c:if test="${purchaselists!=null }">
	      <div class="page">
	      	<c:if test="${pagePurchase!=null }">
		        <div>
		          <a class="prev" href="${pageContext.request.contextPath }/findPurchaselistByPage.action?pageNum=1&purchaselist.purchaseTime=${pagePurchase.purchaseTime }&purchaselist.purchaseId=${pagePurchase.purchaseId}&purchaselist.invoiceNumber=${purchaselist.invoiceNumber}&purchaselist.supplierName=${purchaselist.supplierName}&purchaselist.purchasePerson=${purchaselist.purchasePerson}">首页</a>
		          <c:if test="${pageNum-1>0 }">
		            <a class="prev" href="${pageContext.request.contextPath }/findPurchaselistByPage.action?pageNum=${pageNum-1 }&purchaselist.purchaseTime=${pagePurchase.purchaseTime }&purchaselist.purchaseId=${pagePurchase.purchaseId}&purchaselist.invoiceNumber=${purchaselist.invoiceNumber}&purchaselist.supplierName=${purchaselist.supplierName}&purchaselist.purchasePerson=${purchaselist.purchasePerson}">&lt;&lt;</a>
		          </c:if>
		          <!-- 以当前页为中心，前后各显示3页 -->
					<c:set var="begin" value="1" scope="page"/>
					<c:set var="end" value="${pages }" scope="page"/>
					<!-- 判断当前页前是否有3页 -->
					<c:if test="${pageNum - 3 >0 }">
						<c:set var="begin" value="${pageNum - 3 }" scope="page"/>
					</c:if>
					<!-- 判断当前页后是否有3页 -->
					<c:if test="${pageNum+3<pages }">
						<c:set var="end" value="${pageNum+3 }" scope="page"/>
					</c:if>
		          <c:forEach begin="${begin }" end="${end }" step="1" var="i">
				  	<c:if test="${pageNum==i }">
				  		<span class="current">${i}</span>
				  	</c:if>
				  	<c:if test="${pageNum!=i }">
				  		<a class="num" href="${pageContext.request.contextPath }/findPurchaselistByPage.action?pageNum=${i}&purchaselist.purchaseTime=${pagePurchase.purchaseTime }&purchaselist.purchaseId=${pagePurchase.purchaseId}&purchaselist.invoiceNumber=${purchaselist.invoiceNumber}&purchaselist.supplierName=${purchaselist.supplierName}&purchaselist.purchasePerson=${purchaselist.purchasePerson}">${i}</a>
				  	</c:if>
				  </c:forEach>
				  <c:if test="${pageNum+1<=pages }">
						<a class="next" href="${pageContext.request.contextPath }/findPurchaselistByPage?pageNum=${pageNum+1 }&purchaselist.purchaseTime=${pagePurchase.purchaseTime }&purchaselist.purchaseId=${pagePurchase.purchaseId}&purchaselist.invoiceNumber=${purchaselist.invoiceNumber}&purchaselist.supplierName=${purchaselist.supplierName}&purchaselist.purchasePerson=${purchaselist.purchasePerson}">&gt;&gt;</a>	   
				  </c:if>
				  <a class="next" href="${pageContext.request.contextPath }/findPurchaselistByPage.action?pageNum=${pages }&purchaselist.purchaseTime=${pagePurchase.purchaseTime }&purchaselist.purchaseId=${pagePurchase.purchaseId}&purchaselist.invoiceNumber=${purchaselist.invoiceNumber}&purchaselist.supplierName=${purchaselist.supplierName}&purchaselist.purchasePerson=${purchaselist.purchasePerson}">末页</a>
		        </div>
	        </c:if>
	        <c:if test="${pagePurchase==null }">
		        <div>
		        	<a class="prev" href="${pageContext.request.contextPath }/findPurchaselistByPage.action?pageNum=1">首页</a>
		            <c:if test="${pageNum!=1 }">
		             <a class="prev" href="${pageContext.request.contextPath }/findPurchaselistByPage.action?pageNum=${pageNum-1 }">&lt;&lt;</a>
		            </c:if>
		          	<!-- 以当前页为中心，前后各显示3页 -->
					<c:set var="begin" value="1" scope="page"/>
					<c:set var="end" value="${pages }" scope="page"/>
					<!-- 判断当前页前是否有3页 -->
					<c:if test="${pageNum - 3 >0 }">
						<c:set var="begin" value="${pageNum - 3 }" scope="page"/>
					</c:if>
					<!-- 判断当前页后是否有3页 -->
					<c:if test="${pageNum+3<pages }">
						<c:set var="end" value="${pageNum+3 }" scope="page"/>
					</c:if>
			        <c:forEach begin="${begin }" end="${end }" step="1" var="i">
					  	<c:if test="${pageNum==i }">
					  		<span class="current">${i}</span>
					  	</c:if>
					  	<c:if test="${pageNum!=i }">
					  		<a class="num" href="${pageContext.request.contextPath }/findPurchaselistByPage.action?pageNum=${i}">${i}</a>
					  	</c:if>
					</c:forEach>
				    <c:if test="${pageNum+1!=pages }">
						<a class="next" href="${pageContext.request.contextPath }/findPurchaselistByPage?pageNum=${pageNum+1 }">&gt;&gt;</a>	   
				    </c:if>
				    <a class="next" href="${pageContext.request.contextPath }/findPurchaselistByPage?pageNum=${pages }">末页</a>
		        </div>
	        </c:if>
	      </div>
      </c:if>
      
      

    </div>
    <script>
      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#purchaseTime' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });

       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要停用吗？',function(index){

              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

              }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
              }
              
          });
      }

      /*用户-删除*/
      function member_del(obj,id){
    	  
          layer.confirm('确认要删除吗？',function(index){
        	  $.ajax({
        			url:"delPurchase",
        			type:"post",
        			data:{"purchaselist.purchaseId":id},
        			success:function(data){
        				var backdata=JSON.parse(data);
        				if(backdata.msg=="ok"){
        				    console.log("OK");
        				    layer.alert("删除成功", {icon: 6},function () {
        				    	layer.closeAll('dialog');
          		            });
        				}else{
        					console.log("ERROR");
        					layer.alert("删除失败", {icon: 6},function () {
        						layer.closeAll('dialog');
          		            });
        				}
        			} 
        		  });
              $(obj).parents("tr").remove();
          });
      }



      function delAll (argument) {

        var data = tableCheck.getData();
  
        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>

  </body>

</html>